find the kth max and min element of an array